#include "pushbutton_01.h"
#include<QDebug>
#include<QString>
#include<QPropertyAnimation>
PushButton_01::PushButton_01(QString normalImg,QString pressImg,int x)
{
    this->normalPath = normalImg;
    this->pressPath = pressImg;
    QPixmap pix;
    pix.load(this->normalPath);
    if(x==0)
    {
        this->setFixedSize(pix.width(),pix.height());
    }
    else
    {
        this->setFixedSize(1020,1000);
    }
    //不规则样式
    this->setStyleSheet("QPushButton{border:0px;}");
    //设置图标
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));
}

//下跳
void PushButton_01::zoom1()
{
    QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
    animation->setDuration(200);
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start(QAbstractAnimation::DeleteWhenStopped);
}

void PushButton_01::zoom2()
{
    QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
    animation->setDuration(200);
    animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start(QAbstractAnimation::DeleteWhenStopped);
}

void PushButton_01::mousePressEvent(QMouseEvent *e)
{
    if(this->pressPath!="")
    {
        QPixmap pix;
        bool ret = pix.load(this->pressPath);
        if(!ret){
            QString str = QString("图标加载失败！路径为%1").arg(this->pressPath);
            qDebug()<<str;
        }

        this->setFixedSize(pix.width(),pix.height());
        //不规则样式
        this->setStyleSheet("QPushButton{border:0px;}");
        //设置图标
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
    }

    //其他事情给父类处理
    QPushButton::mousePressEvent(e);
}

void PushButton_01::mouseReleaseEvent(QMouseEvent *e)
{
    if(this->pressPath!="")
    {
        QPixmap pix;
        bool ret = pix.load(this->normalPath);
        if(!ret){
            QString str = QString("图标加载失败！路径为%1").arg(this->normalPath);
            qDebug()<<str;
        }

        this->setFixedSize(pix.width(),pix.height());
        //不规则样式
        this->setStyleSheet("QPushButton{border:0px;}");
        //设置图标
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
    }

    //其他事情给父类处理
    QPushButton::mouseReleaseEvent(e);
}
